package com.cxyzy.demo;

import android.Manifest;
import android.annotation.SuppressLint;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;

import com.blankj.utilcode.util.PhoneUtils;
import com.tbruyelle.rxpermissions2.Permission;
import com.tbruyelle.rxpermissions2.RxPermissions;

import org.w3c.dom.Text;

import io.reactivex.functions.Consumer;

public class MainActivity extends AppCompatActivity {

    private TextView textView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        textView = findViewById(R.id.textView);

        checkPermissionAndGetDevice();
    }

    @SuppressLint("CheckResult")
    public void checkPermissionAndGetDevice() {
        RxPermissions permissions = new RxPermissions(this);
        permissions.setLogging(true);
        permissions.requestEach(Manifest.permission.READ_PHONE_STATE)
                .subscribe(new Consumer<Permission>() {
                    @SuppressLint("MissingPermission")
                    @Override
                    public void accept(Permission permission) {
                        textView.setText("deviceId: " + PhoneUtils.getDeviceId());
                    }
                });
    }
}
